/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rpt.lib.relatorio;

import java.awt.Color;
import net.sf.jasperreports.engine.JRBand;
import net.sf.jasperreports.engine.JRSection;
import net.sf.jasperreports.engine.design.JRDesignGroup;
import net.sf.jasperreports.engine.design.JRDesignSection;

/**
 *
 * @author Roberto
 */
public class CGrupoRelatorio extends JRDesignGroup {
    //

    CRelatorioBasico fRelatorio = null;
    //
    protected JRSection fSecaoCabecalho = null;
    protected JRSection fSecaoRodape = null;
    //
    protected int fBandaCabecalhoH = 0;
    protected int fBandaRodapeH = 0;
    //
    protected CEstiloRelatorio fEstiloCabecalho = null;
    protected CEstiloRelatorio fEstiloRodape = null;
    //
    protected String fNomeFonte = "Arial";
    //

    public CGrupoRelatorio(
            final CRelatorioBasico aRelatorio,
            boolean aLiberarPreparacao,
            final String aExpressaoGrupo) {
        super();
        fRelatorio = aRelatorio;
        this.setName(toString());
        if (aExpressaoGrupo != null)
            this.setExpression(CBibliotecaRelatorio.expressao(aExpressaoGrupo, String.class));
        preparar(aLiberarPreparacao);
    }
    //

    public void preparar(boolean aLiberarPreparacao) {
        if (aLiberarPreparacao) {
            prepararEstilos(fNomeFonte, "Verdana", "Cp1252");
            prepararAlturas();
            prepararBandas();
        }
    }
    //

    public void prepararEstilos(
            String aNomeFonte,
            String aNomeFontePdf,
            String aCodificacaoPdf) {
        //
        fEstiloCabecalho =
                CEstiloRelatorio.estilo("cabecalho_grupo", aNomeFonte, 12, false, Color.black, Color.white, aNomeFontePdf, aCodificacaoPdf, false, true);
        //
        fEstiloRodape =
                CEstiloRelatorio.estilo("rodape_grupo", aNomeFonte, 12, false, Color.black, Color.white, aNomeFontePdf, aCodificacaoPdf, false, true);
    }
    //

    protected void prepararAlturas() {
    }
    //

    protected void prepararBandas() {
        prepararSecaoCabecalho(fBandaCabecalhoH);
        prepararSecaoRodape(fBandaRodapeH);
    }
    //

    public void prepararSecaoCabecalho(int aAltura) {
        JRDesignSection ds = (JRDesignSection)getGroupHeaderSection();
        ds.addBand(new CBandaRelatorio(fRelatorio,fEstiloRodape));
        /*
        fSecaoCabecalho = secao(
        BandTypeEnum.GROUP_HEADER,aAltura,fEstiloCabecalho);
         * 
         */
    }
    //

    public void prepararSecaoRodape(int aAltura) {
        JRDesignSection ds = (JRDesignSection)getGroupFooterSection();
        ds.addBand(new CBandaRelatorio(fRelatorio,fEstiloCabecalho));
        /*
        fSecaoRodape = secao(
        BandTypeEnum.GROUP_FOOTER,aAltura,fEstiloRodape);
         */
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    /*
    public CSecaoRelatorio secao(
    final BandTypeEnum aTipoBanda,
    //final CRelatorioJasperDesign.enumTipoBanda aTipoBanda, 
    final int aAlturaPx, final CEstiloRelatorio aEstilo) {
    CSecaoRelatorio jrdb = new CSecaoRelatorio(
    new JROrigin(aTipoBanda),fRelatorio,aEstilo);
    ((CBandaRelatorio)jrdb.getBands()[0]).setHeight(aAlturaPx);
    return jrdb;
    }
     */

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public CBandaRelatorio getBanda(final JRSection aSecao, final int aIndice) {
        JRBand[] b = aSecao.getBands();
        if ((aIndice < 0) || (aIndice >= b.length)) {
            return null;
        } else {
            return (CBandaRelatorio) b[aIndice]; // fSecaoCabecalho.getBanda();
        }
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public CBandaRelatorio getBandaCabecalho(final int aIndice) {
        return getBanda(getGroupHeaderSection(),aIndice);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public CBandaRelatorio getBandaRodape(final int aIndice) {
        return getBanda(getGroupFooterSection(),aIndice);
    }
}
